package ut.res;
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.IOException;
public class MessageType{
	// 付費案件流程
	public static final int APPLY_TASK_INVITATION = 1;
	public static final int TASK_APPLIED = 2;
	public static final int GET_TASK = 3;
	public static final int TASK_REVOKED = 4;
	public static final int TASK_ABANDONED = 5;
	public static final int TASK_TRANSLATED = 6;
	public static final int TASK_REJECTED = 7;
	public static final int TASK_ACCEPTED = 8;
	// 付費案件評價邀請
	public static final int TASK_EVALUATION_INVITATION = 9;
	// 付費案件問答
	public static final int TASK_QUESTION = 21;
	public static final int TASK_ANSWER = 22;
	// 付費案件討論
	public static final int DISCUSSION_EMPLOYER = 31;
	public static final int DISCUSSION_TRANSLATOR = 32;
	// 免費案件相關
	public static final int FREE_TASK_PICKED = 41;
	private static HashMap<Integer, MessageType> messageTypes = null;
	static{
		messageTypes = new HashMap<Integer, MessageType>();
		BufferedReader reader = null;
		try{
			reader = new BufferedReader(new InputStreamReader(new FileInputStream(System.getProperty("ut.resource") + "message_type.txt"), "utf-8"));
			String line;
			String[] data;
			MessageType messageType;
			while((line = reader.readLine()) != null){
				if(line.startsWith("#")){
					continue;
				}
				data = line.split("\t");
				messageTypes.put(Integer.parseInt(data[0]), new MessageType(data[1], data[2]));
			}
		}catch(IOException e){
			e.printStackTrace();
		}finally{
			try{
				if(reader != null){
					reader.close();
				}
			}catch(IOException e){
				e.printStackTrace();
			}
		}
	}
	public static MessageType getMessageType(int id){
		return messageTypes.get(id);
	}
	public static String getFilledContent(MessageType messageType, String[] args){
		String content = messageType.content;
		for(int i = 0; i < args.length; i++){
			content = content.replace("[" + i + "]", args[i]);
		}
		return content;
	}
	/* Instance Definition */
	public String subject;
	public String content;
	public MessageType(String subject, String content){
		this.subject = subject;
		this.content = content;
	}
}